from common import *

import os
import sys
from subprocess import Popen, PIPE
import pickle

default_data = {'title':'Joystick', 'info':'Navigate ...'}

def setup(data = default_data):
    import wx
    dlg = wx.TextEntryDialog(None, 'Title: ', 'Configure Process', data['title'])        
    if dlg.ShowModal() == wx.ID_OK:
        data['title'] = dlg.GetValue()
    dlg.Destroy()

    dlg = wx.TextEntryDialog(None, 'Info: ', 'Configure Process', data['info'])        
    if dlg.ShowModal() == wx.ID_OK:
        data['info'] = dlg.GetValue()
    dlg.Destroy()
    
    return data

def InteractiveJoystickFunc(out0 , data = default_data):
    
    
    # Create dialog
    cmd = sys.path[0] + '/extensions/actions/joystick.py "'+data['title']+'" "'+data['info']+'"'
    p = Popen(cmd, shell=True, bufsize=0,
              stdin=None, stdout=PIPE, close_fds=True)
    child_stdout = p.stdout

    l = child_stdout.readline()
    while l:
        out0(l.strip())
        l = child_stdout.readline()
        
    child_stdout.close()
    
    poison(out0)
